package net.mcreator.compresstools.procedures;

import net.minecraft.world.World;
import net.minecraft.world.IWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.entity.Entity;
import net.minecraft.block.Block;

import net.mcreator.compresstools.item.CompressWoodPickaxeItem;
import net.mcreator.compresstools.CompressToolsMod;

import java.util.Map;

public class CompressWoodPickaxeBreakedProcedure {

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("world") == null) {
			if (!dependencies.containsKey("world"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency world for procedure CompressWoodPickaxeBreaked!");
			return;
		}
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency x for procedure CompressWoodPickaxeBreaked!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency y for procedure CompressWoodPickaxeBreaked!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency z for procedure CompressWoodPickaxeBreaked!");
			return;
		}
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency entity for procedure CompressWoodPickaxeBreaked!");
			return;
		}
		IWorld world = (IWorld) dependencies.get("world");
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		Entity entity = (Entity) dependencies.get("entity");
		double fx = 0;
		double fy = 0;
		double fz = 0;
		double nx = 0;
		double nz = 0;
		fx = (entity.getPersistentData().getDouble("fx"));
		fy = (entity.getPersistentData().getDouble("fy"));
		fz = (entity.getPersistentData().getDouble("fz"));
		if (CompressWoodPickaxeItem.block.canHarvestBlock((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))))) {
			if (0 == fy) {
				if (!(0 == fx)) {
					fx = 0;
					fz = 1;
				} else {
					fx = 1;
					fz = 0;
				}
				nx = (x + fx);
				fy = (y - 1);
				nz = (z + fz);
				for (int index0 = 0; index0 < (int) (3); index0++) {
					for (int index1 = 0; index1 < (int) (3); index1++) {
						if (!BlockTags.getCollection().getTagByID(new ResourceLocation("forge:unbreak"))
								.contains((world.getBlockState(new BlockPos((int) nx, (int) fy, (int) nz))).getBlock())) {
							if (world instanceof World) {
								Block.spawnDrops(world.getBlockState(new BlockPos((int) nx, (int) fy, (int) nz)), (World) world,
										new BlockPos((int) nx, (int) fy, (int) nz));
								world.destroyBlock(new BlockPos((int) nx, (int) fy, (int) nz), false);
							}
						}
						nx = (nx - fx);
						nz = (nz - fz);
					}
					nx = (x + fx);
					nz = (z + fz);
					fy = (fy + 1);
				}
			} else {
				fx = (x + 1);
				fy = y;
				fz = (z + 1);
				for (int index2 = 0; index2 < (int) (3); index2++) {
					for (int index3 = 0; index3 < (int) (3); index3++) {
						if (!BlockTags.getCollection().getTagByID(new ResourceLocation("forge:unbreak"))
								.contains((world.getBlockState(new BlockPos((int) fx, (int) fy, (int) fz))).getBlock())) {
							if (world instanceof World) {
								Block.spawnDrops(world.getBlockState(new BlockPos((int) fx, (int) fy, (int) fz)), (World) world,
										new BlockPos((int) fx, (int) fy, (int) fz));
								world.destroyBlock(new BlockPos((int) fx, (int) fy, (int) fz), false);
							}
						}
						fx = (fx - 1);
					}
					fx = (x + 1);
					fz = (fz - 1);
				}
			}
		}
		entity.getPersistentData().putBoolean("bkd", (true));
	}
}
